package com.samp.base.file.diff;

import com.samp.util.FilesUtils;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;


/**
 * 找出两个文件夹中不同的文件。
 * @param
 */
public class FindDiffFiles {
	
	/**
	 * 从文件中解析出文件名。
	 * @param
	 * @return
	 */
	public static List<String> getFilesFromTxt(String filePath) throws Exception{
			BufferedReader  br = Files.newBufferedReader(Paths.get(filePath));
			if( br == null ){
				throw new FileNotFoundException(filePath +" is null");
			}
			List<String> list = new ArrayList<>();
			String line = br.readLine();
			while( line != null ){
				String fileName = line.substring(line.lastIndexOf("\\")+1);
				list.add(fileName);
				//System.out.println(fileName);
				line = br.readLine();
			}
			return list;
		
	}
	
	public static List<String> getFilesFromDir(String dirPath) throws Exception{
		return FilesUtils.getFilesFromDir(dirPath);
	}

	public static void main(String[] args) {
		String filePath = "src/main/java/com/samp/base/file/diff/filepaths.txt";
		String dirPath = "D:\\solrCloud\\tomcat\\apache-tomcat-8.5.31-8180\\webapps\\solr\\WEB-INF\\lib\\";
		try {
			List<String> fileList = getFilesFromTxt(filePath);
			System.out.println("fileList size = "+fileList.size());
			List<String> dirList = getFilesFromDir(dirPath);
			System.out.println("dirList size = "+dirList.size());
			//dirList.removeAll(fileList);
			//System.out.println("dirList size = "+dirList.size());
			fileList.removeAll(dirList);
			System.out.println("fileList size = "+fileList.size());
			System.out.println(dirList);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
